//
//  ABTabBuuton.m
//  ZYTS-iPhone
//
//  Created by yuzhou on 12-12-6.
//  Copyright (c) 2012年 wzyk. All rights reserved.
//

#import "ABTabButton.h"

@implementation ABTabButton

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
    }
    return self;
}

- (id)initWithImage:(UIImage *)image highlightedImage:(UIImage *)highlightedImage title:(NSString *)title
{
    self = [super initWithFrame:CGRectMake(0, 0, TabButtonWidth, TabButtonHeigth)];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        
        aButton = [UIButton buttonWithType:UIButtonTypeCustom];
        aButton.frame = self.bounds;
        [aButton setBackgroundImage:[UIImage imageNamed:@"main_tab_selected"] forState:UIControlStateSelected];
//        [aButton setBackgroundImage:[UIImage imageNamed:@"main_tab_selected"] forState:UIControlStateHighlighted];
        [self addSubview:aButton];
        
        bButton = [UIButton buttonWithType:UIButtonTypeCustom];
        bButton.frame = self.bounds;
        bButton.hidden = YES;
        [self addSubview:bButton];
        
        aImageView = [[[UIImageView alloc] initWithFrame:CGRectMake(17, 1, 30, 30)] autorelease];
        aImageView.image = image;
        aImageView.highlightedImage = highlightedImage;
        [self addSubview:aImageView];
        
        UILabel *label = [[[UILabel alloc] initWithFrame:CGRectMake(19.5, 29, 25, 15)] autorelease];
        label.text = title;
        label.textColor = [UIColor whiteColor];
        label.textAlignment = UITextAlignmentCenter;
        label.font = [UIFont systemFontOfSize:10];
        label.backgroundColor = [UIColor clearColor];
        [self addSubview:label];
    }
    return self;
}

- (void)addTarget:(id)target action:(SEL)action
{
    [aButton addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    [bButton addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
}

- (void)setTag:(NSInteger)tag
{
    [super setTag:tag];
    aButton.tag = tag;
    bButton.tag = tag;
}

- (void)setSelected:(BOOL)selected
{
    aButton.selected = selected;
    aImageView.highlighted = selected;
    bButton.hidden = !selected;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end
